// components/cell/cell-check/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    color: {
      type: String,
      value: ''
    },
    title: {
      type: String,
      value: ''
    },
    list: {
      type: Array,
      value: []
    },
    select: {
      type: Array,
      value: []
    },
    choice: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    activeNames: [],
    isOpen: false,
    selectName: '',
    noShare: false,

  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      this.setData({
        activeNames: event.detail,
      });
    },
    onOpen() {
      this.setData({
        isOpen: true
      })

    },
    onClose() {
      this.setData({
        isOpen: false
      })

    },
    onChangecheckbox(event) {
      const arr = event.detail.filter(item => item!='0')
      this.triggerEvent('selectFn', arr)
    },
    onChangeNo(event) {
      let arr = event.detail ? ['0'] : []
      this.triggerEvent('selectFn', arr)
    }
  },
  observers: {
    'select': function (e) {
      let arr = e
      let selectName = '请选择'
      let noShare=false
      if (arr.length && arr[0]!='0') {
        const list = this.data.list
        selectName = list.filter(item => arr.includes(item.value)).map(item => item.name)
        noShare=false
      } else if (arr.length) {
        selectName = this.data.choice
        noShare=true
      }
      this.setData({
        selectName,
        noShare
      })
    }
  }
})